package com.example.librarymanagersystem.controller;

import com.example.librarymanagersystem.entity.BookInfo;
import com.example.librarymanagersystem.service.BookInfoServie;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller

public class BookInfoController {

    @Autowired
    private BookInfoServie bookInfoServie;

    @GetMapping("/book/info")
    public ModelAndView customerAddView() {
        ModelAndView mav = new ModelAndView("/book/info");
        return mav;
    }

    @RequestMapping("/book/info")
    public ModelAndView customerListView(
            @RequestParam(name = "pageNum", required = true, defaultValue = "1") int pageNum,
            @RequestParam(name = "pageSize", required = true, defaultValue = "5") int pageSize,
            @RequestParam(name = "keyword", required = false) String keyword
    ) {
        ModelAndView mav = new ModelAndView("/book/info");
        //检索出客户信息数据，并设置到环境中
        //第一次显示客户信息，第一页显示
        PageInfo<BookInfo> page = bookInfoServie.findBykeyword(pageNum, pageSize, keyword);
//        System.out.println(page);
        mav.addObject("page", page);
        return mav;
    }
}
